openerp.product_qt = function(instance){
/*	var _t = instance.web._t, 
		_lt = instance.web._lt;
    var QWeb = instance.web.qweb;*/
    instance.web.form.widgets.add('one2many_checkboxes', 'instance.product_qt.one2many_checkboxes');
    instance.product_qt.one2many_checkboxes = instance.web.form.FieldOne2Many.extend({
    	multi_selection: true,
    	
        init: function(field_manager, node) {
            this._super(field_manager, node);
        }, 
        
    	build_context: function() {
    		this._super.apply(this, arguments);
    	},
    	
    	get_value: function() {
    		this._super.apply(this, arguments);
    	},
    	
    	get_selected_ids: function() {
	        var ids = [];
	        if (this.viewmanager && this.viewmanager.views && this.viewmanager.active_view &&
	                this.viewmanager.views[this.viewmanager.active_view] &&
	                this.viewmanager.views[this.viewmanager.active_view].controller) {
	                var view = this.viewmanager.views[this.viewmanager.active_view].controller;
	                if (this.viewmanager.active_view === "list") {
	                    ids = view.get_selected_ids();
	                }
	            }
	        return ids;
    	}
    });
    
    /*instance.web.form.tags.add('custom', 'instance.product_qt.button_custom');*/
    
    instance.web.form.custom_widgets.add('button_custom', 'instance.product_qt.button_custom');
    instance.product_qt.button_custom = instance.web.form.WidgetButton.extend({
    	init: function(field_manager, node) {
    		node.attrs['type'] = 'button';
    		node.attrs['data-button-type'] = node.attrs['button_type'];
            this._super(field_manager, node);
        },
        
    	on_confirmed: function() {
            var self = this;
            var context = this.build_context();
            
            if (self.field_manager && self.field_manager.fields ){
            	_.each(self.field_manager.fields, function(field) {
                    if (field.widget === 'one2many_checkboxes'){
                    	var ids = field.get_selected_ids();
                    	if (ids.length > 0){
                    		var keyval = {};
                    		keyval[field.name + '_selected'] = ids;
                    		context.add(keyval);
                    	}
                    }             
            	});            	
            };
            return this.view.do_execute_action(
                _.extend({}, this.node.attrs, {context: context}),
                this.view.dataset, this.view.datarecord.id, function (reason) {
                    if (!_.isObject(reason)) {
                        self.view.recursive_reload();
                    }
                });
        }
    });
};